﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Collections;
using WorkflowWizart.Lib.Utility.Costants;

namespace WorkflowWizart.Lib.Utility.ExtensionMethods
{
    public static class ObjectExtender
    { 
        public static T To<T>(this object data)
        {
            return ConvertHelper.To<T>(data);
        }

        public static T ToEnum<T>(this object data)
        {
            return (T)ConvertHelper.ParseEnum(typeof(T), data);
        }

        public static bool IsNullOrDefault(this object data)
        {
            return CompareHelper.IsNullOrDefault(data);
        } 

        public static bool IsGuidsCompares(this object data, object toData)
        {
            return CompareHelper.IsGuidsCompares(data, toData);
        }

        public static string ToStringData(this object data)
        {
            return ConvertHelper.ToString(data);
        }

        public static object[] ToObjectArray(this object data)
        {
            return ConvertHelper.ToObjectArray(data);
        }

        public static bool ToBool(this object data)
        {
            return ConvertHelper.ToBool(data);
        }

        public static Guid ToGuid(this object data)
        {
            Guid toData = Guid.Empty;
            if (!ConvertHelper.TryParseToGuid(data, out toData))
            {
                toData = Guid.Empty;
            }
            return toData;
        }

        public static bool TryParseToGuid(this object data, out Guid toData)
        {
            return ConvertHelper.TryParseToGuid(data, out toData);
        }

        public static DateTime ToDateTime(this object data)
        {
            return ConvertHelper.ToDateTime(data);
        }

        public static DateTime ToLocalDateTime(this object data)
        {
            return ConvertHelper.ToDateTime(data).ToLocalTime();
        }

        public static DateTime ToUniversalDateTime(this object data)
        {
            return ConvertHelper.ToDateTime(data).ToUniversalDateTime();
        }

        public static DateTime GetDefaultDateTimeValue()
        {
            return TypeValues.DateTimeDefaultValue;
        }

        public static int ToInt(this object data)
        {
            return ConvertHelper.ToInt(data);
        }

        public static long ToLong(this object data)
        {
            return ConvertHelper.ToLong(data);
        }

        public static decimal ToDecimal(this object data)
        {
            return ConvertHelper.ToDecimal(data);
        }

        public static float ToFloat(this object data)
        {
            return ConvertHelper.ToFloat(data);
        }

        public static short ToShort(this object data)
        {
            return ConvertHelper.ToShort(data);
        }

        public static double ToDouble(this object data)
        {
            return ConvertHelper.ToDouble(data);
        }

        public static int ConvertToCollectionAndGetCount(this object data)
        {

            if (data is IList)
            {
                var listData = data as IList;
                if (listData != null)
                {
                    return listData.Count;
                }
            }

            if (data is ICollection)
            {
                var listData = data as ICollection;
                if (listData != null)
                {
                    return listData.Count;
                }
            }

            if (data is Array)
            {
                var listData = data as Array;
                if (listData != null)
                {
                    return listData.Length;
                }
            }

            if (data is ArrayList)
            {
                var listData = data as ArrayList;
                if (listData != null)
                {
                    return listData.Count;
                }
            }

            if (data != null)
            {
                return 1;
            }
            return 0;

        }
    }
}
